require 'map_editor/palet_panel'
require 'map_editor/auto_palet_panel'
require 'map_editor/normal_palet_panel'
require 'map_editor/anime_palet_panel'

module MapEditor
  class PaletNotebook < Gtk::Notebook
    attr_reader :palets, :mode
    def initialize
      super()
      
      @mode = :palet_picker
      
      self.tab_pos = Gtk::POS_BOTTOM
      
      @palets = Array.new(3)
      @basic_palet_panel = Gtk::VBox.new
      self.append_page(@basic_palet_panel, Gtk::Label.new("Basic"))
      
      @auto_palet_panel = Gtk::VBox.new
      self.append_page(@auto_palet_panel, Gtk::Label.new("Auto"))
      
      @anime_palet_panel = Gtk::VBox.new
      self.append_page(@anime_palet_panel, Gtk::Label.new("Anime"))
      @palet = nil
    end
    
    def mode=(mode)
      @mode = mode
      self.refresh_panel_state
    end

    def clear
      @basic_palet_panel.children.each do |child|
        @basic_palet_panel.remove(child)
      end
      @auto_palet_panel.children.each do |child|
        @auto_palet_panel.remove(child)
      end
      @auto_palet_panel.children.each do |child|
        @auto_palet_panel.remove(child)
      end
    end
    
    def basic_palet_panel=(palet_panel)
      @basic_palet_panel.children.each do |child|
        @basic_palet_panel.remove(child)
      end
      @basic_palet_panel.add(palet_panel)
      palet_panel.render
      @palets[0] = palet_panel
      self.show_all
    end
    
    def auto_palet_panel=(palet_panel)
      @auto_palet_panel.children.each do |child|
        @auto_palet_panel.remove(child)
      end
      @auto_palet_panel.add(palet_panel)
      palet_panel.render
      @palets[1] = palet_panel
      self.show_all
    end
    
    def anime_palet_panel=(palet_panel)
      @anime_palet_panel.children.each do |child|
        @anime_palet_panel.remove(child)
      end
      @anime_palet_panel.add(palet_panel)
      palet_panel.render
      @palets[2] = palet_panel
      self.show_all
    end
    
    def palet
      return @palets[self.page]
    end
    
    def refresh_palets
      @palets.each do |palet|
        palet.render
      end
    end
    
    def set_panel_mode(page, mode, zoom)
      if @palets[page]
        @palets[page].panel_mode = mode
        @palets[page].zoom = zoom
      end
    end
    
    def on_resize(width, height)

    end
  end
end